package com.selenium;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;
import java.util.Set;

public class CookieInterceptor implements ClientHttpRequestInterceptor {

    private final String cookie;

    public CookieInterceptor(String cookie) {
        this.cookie = cookie;
    }

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        HttpHeaders headers = request.getHeaders();
        headers.add("Cookie", cookie);
        return execution.execute(request, body);
    }
}
